Component({
  mixins: [],
  data: {
    animation:'',
		rules:'',
		bg:{
			url:"https://img.alicdn.com/imgextra/i1/4161056916/O1CN01LqJFSr20xZqi6swVT_!!4161056916.png",
			width:680,
			height:671
		},

		queren:{
			url:'https://img.alicdn.com/imgextra/i3/4161056916/O1CN01mZMYkc20xZqZIOo3W_!!4161056916.png'
		},
		
		loca:{
			name:'输入收件人姓名',
			phone:'输入收件人手机号',
			address:'请填写详细地址'
		},

		//填写地址防多触控
		isWarit:false

  },
  props: {
		id:'',
		parDa:''
  },
  onInit(){
		//console.info("1111",this.props.rules)
		
		console.info(this.props)

		let loca={}

		if(
			this.props.parDa 
			&& this.props.parDa.receiverName
			&& this.props.parDa.phone
			&& this.props.parDa.receiverAddress
			&& this.props.parDa.receiverArea
			&& this.props.parDa.receiverCity
			&& this.props.parDa.receiverProvince
			){
				loca.name = this.props.parDa.receiverName;
				loca.phone = this.props.parDa.phone;
				loca.address = this.props.parDa.receiverProvince + this.props.parDa.receiverCity + this.props.parDa.receiverArea + this.props.parDa.receiverAddress;
				loca.receiverAddress = this.props.parDa.receiverAddress
				loca.receiverArea =  this.props.parDa.receiverArea
				loca.receiverCity =  this.props.parDa.receiverCity
				loca.receiverProvince =  this.props.parDa.receiverProvince
				

				this.setData({
					loca:loca
				})
		}

   
  },
  didMount() {
    this.animation = my.createAnimation();

    this.animation.translate('0%','150%').step()
    this.setData({ animation: this.animation.export() })

  },
  didUpdate() {},
  didUnmount() {},
  methods: {



    closeList(){
      
      this.animation.translate('0%','-150%').step()
      this.setData({ animation: this.animation.export() })

      setTimeout(() => {
					

        this.$page.prizePage.setData({
          showAddress:false
				})
				

				// console.info(this.$page)
      }, 400);
		},
		
		getAddress(e){

				if(this.data.isWarit)return

				this.setData({
					isWarit:true
				})

			 	my.authorize({
					scopes: 'scope.addressList',
					success: (res) => {
						my.tb.chooseAddress({
							addAddress: "show",
							searchAddress: "show",
							locateAddress: "show",
							success:(res) => {

								console.info(res)

								let loca = {
									name:res.name,
									phone:res.telNumber,
									provinceName:res.provinceName,
									cityName:res.cityName,
									countyName:res.countyName,
									streetName:res.streetName,
									detailInfo:res.detailInfo,
									address:res.provinceName + res.cityName + res.countyName + res.streetName + res.detailInfo
								}

								this.setData({
									loca:loca,
									isWarit:false
								})

							},
							fail:err => {
								this.setData({
									isWarit:false
								})
							}
						})
					},
				});


		},

		savaAddress(){

			console.info(11)

			let loca = this.data.loca

			getApp().cloud.application.httpRequest({
				'path' : '/api/c/prize/address', 
				'method':'POST',
				'headers':{ "Content-Type":"application/json"},
				'params':{},
				'body':{
								id:this.props.id,
								receiverName:loca.name,
								phone:loca.phone,
								receiverAddress:loca.detailInfo,
								receiverArea: loca.countyName,
								receiverCity: loca.cityName,
								receiverProvince:loca.provinceName
							},
				'exts':{}  }).then(res => {

				console.log("用户领取奖品地址=====>",res);

				//判断是否是正常状态
				if(res.code != 200){
					my.alert({
						content:res.msg
					}) 
				}else{
					console.info('填写地址===》',res)
					my.showToast({content:'保存成功'});

					this.$page.showPrize()
				}
			})
		},

  },
});